/**
 * Package: Char
 *
 * Requires: 
 */

#define CR 0x0D
#define LF 0x0A

/// <summary>Indicates whether a specified character is categorized as a control character.</summary>
/// <param name="ch">A character.</param>
/// <returns>True if ch is a control character; otherwise, false.</returns>
byte Char_IsControl(char ch)
{
    return ch < 32;
}

/// <summary>Indicates whether a specified character is categorized as a digit character.</summary>
/// <param name="ch">A character.</param>
/// <returns>True if ch is a decimal digit; otherwise, false.</returns>
byte Char_IsDigit(char ch)
{
    return ch >= '0' && ch <= '9';
}

/// <summary>Indicates whether a specified character is categorized as a lowercase letter.</summary>
/// <param name="ch">A character.</param>
/// <returns>True if ch is a lowercase letter; otherwise, false.</returns>
byte Char_IsLower(char ch)
{
    return ch >= 'a' && ch <= 'z';
}

/// <summary>Indicates whether a specified character is categorized as an uppercase letter.</summary>
/// <param name="ch">A character.</param>
/// <returns>True if ch is an uppercase letter; otherwise, false.</returns>
byte Char_IsUpper(char ch)
{
    return ch >= 'A' && ch <= 'Z';
}

/// <summary>Indicates whether a specified character is categorized as an alphabetic letter.</summary>
/// <param name="ch">The character to evaluate.</param>
/// <returns>True if ch is a letter; otherwise, false.</returns>
byte Char_IsLetter(char ch)
{
    return Char_IsLower(ch) || Char_IsUpper(ch);
}

/// <summary>Indicates whether a specified character is categorized as an alphabetic letter or a digit.</summary>
/// <param name="ch">A character.</param>
/// <returns>True if ch is a letter or a decimal digit; otherwise, false.</returns>
byte Char_IsLetterOrDigit(char ch)
{
    return Char_IsDigit(ch) || Char_IsLetter(ch);
}

/// <summary>Indicates whether a specified character is categorized as white space.</summary>
/// <param name="ch">A character.</param>
/// <returns>True if ch is white space; otherwise, false.</returns>
byte Char_IsWhitespace(char ch)
{
    return ch == ' ' || ch == 10 || ch == 13;
}

/// <summary>Converts the value of a character to its lowercase equivalent.</summary>
/// <param name="ch">A character.</param>
/// <returns>The lowercase equivalent of ch, or the unchanged value of ch, if ch is already lowercase or not alphabetic.</returns>
char Char_ToLowercase(char ch)
{
    return (Char_IsUpper(ch) ? ch + 32 : ch);
}

/// <summary>Converts the value of a character to its uppercase equivalent.</summary>
/// <param name="ch">A character.</param>
/// <returns>The uppercase equivalent of ch, or the unchanged value of ch, if ch is already uppercase or not alphabetic.</returns>
char Char_ToUppercase(char ch)
{
    return (Char_IsLower(ch) ? ch - 32 : ch);
}